package project3t.android.gui;

import project3t.android.control.Controller;
import project3t.android.data.Person;
import project3t.android.gui.R.id;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditForm extends Activity{
	private Person person;
	private int itemIndex;
	private EditText name, surname, sex, age, email;
	//private Button yes, no;
	
	public EditForm(){}
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.person_edit);
		Bundle bun=getIntent().getExtras();
		itemIndex=bun.getInt("index");
		person=Controller.conroller.getPersonByPos(itemIndex);
		name= (EditText) findViewById(R.id.editName);		
		surname=(EditText) findViewById(R.id.editSurname);
		age=(EditText) findViewById(R.id.editAge);
		sex=(EditText) findViewById(R.id.editSex);
		email=(EditText) findViewById(R.id.editEmail);
		name.setText(person.getName());
		surname.setText(person.getSurname());
		age.setText(String.valueOf(person.getAge()));
		sex.setText(String.valueOf(person.getSex()));
		email.setText(person.getEmail());
//		yes=(Button)findViewById(R.id.Yes);
//		no=(Button)findViewById(id.No);
//		
		
		
		
	}
	public void commit(View view)
	{
		person.setName(name.getText().toString());
		person.setSurname(surname.getText().toString());
		person.setAge(Integer.parseInt(age.getText().toString()));
		person.setName(name.getText().toString());
		person.setEmail(email.getText().toString());
		Controller.conroller.editPerson(itemIndex, person);
		finish();
	}
	
	public void cancel(View view)
	{
		finish();
	}
}
